Skip to content

Conversation

@trillium
Copy link
Member

@trillium trillium commented Aug 22, 2025

Fixes #1638

What changes did you make and why did you make them?

  • Added scripts to /backend/package.json for running the cloneOrSyncCollectionsgs.js and clearDevCollections.js scripts with various flags.
  • The scripts accept the --mock flag and flags for each supported collection:
    • For cloneOrSyncCollectionsgs.js: --projects, --recurring-events
    • For clearDevCollections.js: --projects, --recurring-events, --events, --checkins
  • This makes it easier and more consistent to run these scripts from the command line or via yarn, and helps with developer productivity and onboarding.

Usage Guide

1. Change to the backend directory:

cd backend

2. Use --mock to preview what will happen (no data will be changed):

# clearDevCollections
yarn clearDevCollections --projects --mock
yarn clearDevCollections --recurring-events --mock
yarn clearDevCollections --all --mock

# cloneOrSyncCollectionsgs
yarn cloneOrSyncCollectionsgs --projects --mock
yarn cloneOrSyncCollectionsgs --recurring-events --mock

3. Confirm the output is satisfactory.

4. Remove --mock to run the operation on the live DEV database:

# clearDevCollections
yarn clearDevCollections --projects
yarn clearDevCollections --recurring-events
yarn clearDevCollections --all

# cloneOrSyncCollectionsgs
yarn cloneOrSyncCollectionsgs --projects
yarn cloneOrSyncCollectionsgs --recurring-events

Tip: Always use --mock first to verify what will be deleted or cloned before running the actual operation.


Supported Flags & Environment Variables

For clearDevCollections:

  • --projects Only clear the 'projects' collection
  • --recurring-events Only clear the 'recurringevents' collection
  • --events Only clear the 'events' collection
  • --checkins Only clear the 'checkins' collection
  • --all Clear all supported collections
  • --mock Only print what would be deleted, do not delete
  • --help Show help message and exit
  • (no flags) Show help (safety mode)

For cloneOrSyncCollectionsgs:

  • --projects Clone/sync the 'projects' collection
  • --recurring-events Clone/sync the 'recurringevents' collection
  • --initial Initial clone (insertMany, skip duplicates)
  • --mock Only print what would be written, do not write
  • --help Show help message and exit
  • (no flags) Show help (safety mode)

Requires environment variables:

  • PROD_DB_URI - MongoDB URI for PROD
  • DEV_DB_URI - MongoDB URI for DEV

Example Commands

Preview what would be deleted from all collections (no data is changed):

# clearDevCollections
cd backend
yarn clearDevCollections --all --mock

Actually clear the 'projects' collection:

# clearDevCollections
cd backend
yarn clearDevCollections --projects

Clone projects and recurring events from PROD to DEV (mock mode):

# cloneOrSyncCollectionsgs
cd backend
yarn cloneOrSyncCollectionsgs --projects --mock
yarn cloneOrSyncCollectionsgs --recurring-events --mock

Clone only recurring events (real operation):

# cloneOrSyncCollectionsgs
cd backend
yarn cloneOrSyncCollectionsgs --recurring-events

- Add scripts to /backend/package.json
- Requires flags
    -- accepts flag --mock
    -- accepts flags for each db row eg
        -- cloneOrSyncCollections: --projects, --recurring-events
        -- clearDevCollections: --projects, --recurring-events, events, checkins
@trillium trillium force-pushed the trilliumsmith/prod-project-clone branch from 21ec2ed to c828a8d Compare August 22, 2025 18:33
Copy link
Member

@JackHaeg JackHaeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks GREAT Trillium! Thanks for this :)

@JackHaeg JackHaeg merged commit 365c247 into hackforla:development Sep 23, 2025
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Dev Projects and replace with Prod

2 participants